<?php
/**
 * Plugin Name: Zonthemes Twitter Widget
 * Description: Display Twitter streamming .
 * Version: 0.1
 * Author: Man Nguyen
 * Author URI: http://zonthemes.com/author/michael
 */
add_action( 'widgets_init', 'zonthemes_twitter_widget' );

function zonthemes_twitter_widget() {
	register_widget( 'ZONTHEMES_Twitter_Widget' );
}

class ZONTHEMES_Twitter_Widget extends WP_Widget {

	function ZONTHEMES_Twitter_Widget() {
		$widget_ops = array( 'classname' => 'zonthemes_twitter', 'description' => __('A widget that displays twitter streamming ', 'zonthemes') );
		
		$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'zonthemes-twitter-widget' );
		
		$this->WP_Widget( 'zonthemes-twitter-widget', __('ZON - Twitter Widget', 'zonthemes'), $widget_ops, $control_ops );
	}
	
	function widget( $args, $instance ) {
		extract( $args );
		$unique_id = $args['widget_id'];
		//Our variables from the widget settings.
		$title = apply_filters('widget_title', $instance['title'] );
		$username = $instance['username'];
		$limit = isset( $instance['limit'] ) ? $instance['limit'] : 5;

		echo $before_widget;

		// Display the widget title 
		if ( $title )
			echo $before_title . $title . $after_title;
			
		?><div class="back"><ul id="twitter_update_list_<?php echo $unique_id; ?>"><li></li></ul>
			<p><?php _e( 'Follow', 'zonthemes' ); ?> <a href="http<?php ( is_ssl() ? 's' : '' ) ?>://twitter.com/<?php echo $username; ?>"><strong>@<?php echo $username; ?></strong></a> <?php _e( 'on Twitter', 'zonthemes' ); ?></p></div><div class="clear"></div><?php

		echo zonthemes_twitter_script( $unique_id, $username, $limit ); //Javascript output function
		echo $after_widget;
	}

	//Update the widget 
	 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		//Strip tags from title and name to remove HTML 
		$instance['title'] = strip_tags( $new_instance['title'] );
		$instance['username'] = strip_tags( $new_instance['username'] );
		$instance['limit'] = $new_instance['limit'];

		return $instance;
	}

	
	function form( $instance ) {

		//Set up some default widget settings.
		$defaults = array( 'title' => __('Follow me', 'zonthemes'), 'username' => __('zonthemes', 'zonthemes'), 'limit' => 5 );
		$instance = wp_parse_args( (array) $instance, $defaults ); ?>
		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'zonthemes'); ?></label>
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'username' ); ?>"><?php _e('User Name:', 'zonthemes'); ?></label>
			<input id="<?php echo $this->get_field_id( 'username' ); ?>" name="<?php echo $this->get_field_name( 'username' ); ?>" value="<?php echo $instance['username']; ?>" style="width:100%;" />
		</p>
		<p>
			<label for="<?php echo $this->get_field_id( 'limit' ); ?>"><?php _e('Limits:', 'zonthemes'); ?></label>
			<input id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" value="<?php echo $instance['limit']; ?>" style="width:100%;" />
		</p>
		

	<?php
	}
}

?>